/*
 * Authors: Satnam Alag
 * http://www.manning.com/alag/
 * Copyright -- Collective Intelligence in Action
 * Updated: Filipe Ferraz Salgado  (filipesalgado@hotmail.com)
 *          Alexandre Albano       (aalbano@gmail.com)
 *          Instituto de Matemática e Estatística
 *          Universidade de São Paulo
 * 
 */

package br.org.groupware_workbench.commonalgorithms.analisadortextual_1_1.com.alag.ci.textanalysis.lucene.impl;

import java.io.IOException;
import java.util.*;

import br.org.groupware_workbench.commonalgorithms.analisadortextual_1_1.com.alag.ci.textanalysis.PhrasesCache;

public class PhrasesCacheImpl extends CacheImpl implements PhrasesCache {
    private Map<String,String> validPhrases = null;
    
    public PhrasesCacheImpl(String[] stopWords) throws IOException {
    	super(stopWords);
    	validPhrases = new HashMap<String,String>();
    }
    
    public PhrasesCacheImpl(List<String> listPhrases, String[] stopWords) throws IOException {
    	super(stopWords);
        validPhrases = new HashMap<String,String>();
//        validPhrases.put(getStemmedText("collective intelligence"), null);
        
        if(listPhrases != null) {
        	for (String phrase : listPhrases) {
        		if(!"".equals(phrase)) {
        			validPhrases.put(getStemmedText(phrase), null);
        		}
        	}       
        }
    }
    
    public boolean isValidPhrase(String text) throws IOException {
        return this.validPhrases.containsKey(getStemmedText(text));
    }
}
